<%@ page errorPage="/jsp/exceptionHandler.jsp"%>
<%@page import="com.metagurukul.metaspace.service.UserService"%>
<%@page import="com.metagurukul.metaspace.models.beans.UserWorkDetail"%>
<%@page import="java.sql.SQLException"%>
<%@page
	import="com.metagurukul.metaspace.models.beans.UserPersonalDetail"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Profile Page</title>
<script type="text/javascript" src="../resources/js/jquery.js"></script>
<SCRIPT type="text/javascript">
	$(document).ready(function() {
		if (window != top)
			top.location.href = location.href;
	});

	window.history.forward();
	function noBack() {
		window.history.forward();
	}
	function search() {
		window.open("/jsp/search.jsp?txt="
				+ document.getElementById("searchTxt").value, "content");
	}
	function goHome() {
		window.location = '/jsp/home.jsp';
	}
</SCRIPT>
<link rel="stylesheet" type="text/css"
	href="../resources/css/masterLayoutStyle.css" />
<link rel="stylesheet" href="../resources/css/style.css" />
</head>
<body>
	<div id="header">
		<table style="border: 0; width: 100%; height: 100%">
			<tr>
				<td width="25%" align="center"><a href="/jsp/home.jsp"><img
						src="../resources/images/logo.jpg" /> </a></td>
				<td width="35%" align="center"><input type="text"
					style="font-size: 19px; margin-top: 1px" id="searchTxt" size=23 /><input
					type="button" id="invite" class="btn btn-inverse" value="Search"
					onclick="search()" />
				</td>
				<td width="40%">
					<ul id="mainMenu" class="topmenu">
						<li class="topmenu"><a href="/jsp/home.jsp"
							style="height: 20px; line-height: 20px;"><img
								src="../resources/images/home.png" alt="" />Home</a>
						</li>
						<li class="topmenu"><a href="#"
							style="height: 20px; line-height: 20px;"><span><img
									src="../resources/images/samples.png" alt="" />Settings</span> </a>
							<ul>
								<li><a href="/jsp/profile.jsp" target="content">My
										Profile</a>
								</li>
								<li><a href="/jsp/changePassword.jsp" target="content">Change
										Password</a>
								</li>
								<li><a href="/jsp/personalDetails.jsp" target="content">Edit
										Personal Information</a>
								</li>
								<li><a href="/jsp/workDetails.jsp" target="content">Edit
										Work Details</a>
								</li>
							</ul>
						</li>
						<li class="topmenu"><a href="../Logout"
							style="height: 20px; line-height: 20px;">Sign Out</a>
						</li>
					</ul>
				</td>
			</tr>
		</table>
	</div>
	<div id="container">
		<div id="main" style="margin: auto;">
			<%
				int userId = -1;
				if (request.getParameter("id") != null) {
					userId = Integer.parseInt(request.getParameter("id"));
				}
				UserPersonalDetail userPersonalDetail = UserService
						.getUserPersonalDetail(userId);
				String gender;
				if (userPersonalDetail.getGender() == 'M') {
					gender = "Male";
				} else {
					gender = "Female";
				}
			%>
			<center>
				<img
					src="../resources/images/users/<%=userPersonalDetail.getProfilePicPath()%>"
					width="100px" height="100px"
					alt="<%=userPersonalDetail.getName()%>" />
			</center>
			<fieldset>
				<legend>Basic Details:</legend>
				<table>
					<tr>
						<td width="200px">Full Name</td>
						<td><%=userPersonalDetail.getName()%></td>
					</tr>
					<tr>
						<td>Username</td>
						<td><%=userPersonalDetail.getUserName()%></td>
					</tr>
					<tr>
						<td>Contact</td>
						<td><%=userPersonalDetail.getContact()%></td>
					</tr>
					<tr>
						<td>Gender</td>
						<td><%=gender%></td>
					</tr>
					<tr>
						<td>Date of Birth</td>
						<td><%=userPersonalDetail.getDate()%></td>
					</tr>
				</table>
			</fieldset>
		</div>
		<br> <br>
		<center>
			<div id="workDetail" style="margin: auto;">
				<fieldset style="width: 250px;">
					<legend>Work Details:</legend>
					<%
						UserWorkDetail userWorkDetail = UserService
								.getUserWorkDetail(userId);
						if (userWorkDetail != null) {
					%>

					<table>
						<tr>
							<td width="200px">Department Name</td>
							<td><%=userWorkDetail.getDepartmentName()%></td>
						</tr>
						<tr>
							<td>Project Name</td>
							<td>
								<%
									if (userWorkDetail.getUserProjectList().size() > 0) {
											out.println(userWorkDetail.getUserProjectList().get(0)
													.getProjectName());
										}
								%>
							</td>
						</tr>
						<tr>
							<td>Role</td>
							<td><%=userWorkDetail.getRoleName()%></td>
						</tr>

					</table>

					<%
						} else {
					%>
					<center>Work Details are not yet filled.</center>

					<%
						}
					%>
				</fieldset>
			</div>
		</center>
	</div>
	<jsp:include page="/jsp/footer.jsp"></jsp:include>
</body>
</html>